package com.example.park2301.fangke

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.example.lib_base.entity.FangKeBean
import com.example.lib_base.entity.FangKeBeanItem
import com.example.lib_base.entity.Res
import com.example.lib_base.net.ApiService

class FkDataSource (val apiService: ApiService,val pore:String,val type:String) :PagingSource<Int,FangKeBeanItem>(){
    override fun getRefreshKey(state: PagingState<Int, FangKeBeanItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, FangKeBeanItem> {
        try {
            var res:Res<FangKeBean>?=null
            if (type=="类型"){
                res=apiService.getFang()
            }else if (type=="搜索"){
                res=apiService.getSou(pore)
            }
            return LoadResult.Page(res?.data!!,null,null)
        }catch (e:Exception){
            return LoadResult.Error(e)
        }
    }
}